<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="true" />














  
  
    
  
  <link href="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.lug.ustc.edu.cn/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico?v=5.1.2" />






<meta name="description" content="重度拖延症患者(-__-)b">
<meta property="og:type" content="website">
<meta property="og:title" content="混饭&#39;s Notes">
<meta property="og:url" content="http://hunfan.top/page/5/index.html">
<meta property="og:site_name" content="混饭&#39;s Notes">
<meta property="og:description" content="重度拖延症患者(-__-)b">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="混饭&#39;s Notes">
<meta name="twitter:description" content="重度拖延症患者(-__-)b">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '77ZW8HG1F0',
      apiKey: '924aaf9b16831d3af864330abb1b94cf',
      indexName: 'github',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":"找不到关于” ${query} ”的文章","hits_stats":"共找到 ${hits} 篇文章，花了 ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://hunfan.top/page/5/"/>



<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>



	<meta name="google-site-verification" content="7cmTqceXKE0HPzXSCTPWvChlMw-OZuC3GLENr9qj9XM" />


  <title>混饭's Notes</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>
	<a target="_blank" href="https://github.com/hf-hf" class="github-corner" aria-label="Fork me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
	
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">混饭's Notes</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Quick notes</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/07/13/Git commit-your-changes-or-stash-them-before-you-can-merge/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/07/13/Git commit-your-changes-or-stash-them-before-you-can-merge/" itemprop="url">Git：commit your changes or stash them before you can merge</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-07-13T17:52:06+08:00">
                2018-07-13
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/07/13/Git commit-your-changes-or-stash-them-before-you-can-merge/" class="leancloud_visitors" data-flag-title="Git：commit your changes or stash them before you can merge">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git stash</span><br><span class="line">git pull</span><br><span class="line">git stash pop</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/06/27/Mysql新建表提示Row-size-too-large-8126/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/27/Mysql新建表提示Row-size-too-large-8126/" itemprop="url">Mysql新建表提示Row size too large (> 8126)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-27T16:59:32+08:00">
                2018-06-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/运维日志/" itemprop="url" rel="index">
                    <span itemprop="name">运维日志</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/06/27/Mysql新建表提示Row-size-too-large-8126/" class="leancloud_visitors" data-flag-title="Mysql新建表提示Row size too large (> 8126)">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="情景"><a href="#情景" class="headerlink" title="情景"></a>情景</h2><p>Mysql新增数据表，字段类型为varchar长度较长，且该类型字段较多有200多个，进行create时报错Row size too large (&gt; 8126)。</p>
<h2 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h2><p>在新建数据表create语句前追加：set innodb_strict_mode=0;再新建即可。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/06/21/Idea修改import顺序，与Eclipse一致/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/21/Idea修改import顺序，与Eclipse一致/" itemprop="url">Idea修改import顺序，与Eclipse一致</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-21T18:25:50+08:00">
                2018-06-21
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/06/21/Idea修改import顺序，与Eclipse一致/" class="leancloud_visitors" data-flag-title="Idea修改import顺序，与Eclipse一致">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="情景："><a href="#情景：" class="headerlink" title="情景："></a>情景：</h2><p>之前切换到Idea之后，一直在和身边的人安利，但是总有部分顽固分子（偷瞄一眼对面的同学 0.0）还在使用Eclipse，Idea和Eclipse提交同一个Java文件，会导致import部分顺序不一致，提交时进行比对时会发现很多报红的，其实只是引用顺序换了换而已。</p>
<h2 id="调查："><a href="#调查：" class="headerlink" title="调查："></a>调查：</h2><p>上网搜了一下，发现Idea可以调整import的顺序，具体配置在：Settings -&gt; code style -&gt; java -&gt; imports。</p>
<h2 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h2><p>调整Settings -&gt; code style -&gt; java -&gt; imports下的引用顺序，改为如下：<br><img src="/upload/changeImport/change_import_1.png" alt="change_import_1.png"><br>另外Idea默认会将超过一定数量的import，自动合并成import *，修改不进行合并也是在此处，将下图中的两个数值改到999，点击保存即可。<br><img src="/upload/changeImport/change_import_2.png" alt="change_import_2.png">   </p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/06/21/Linux下查看文件内容的指令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/21/Linux下查看文件内容的指令/" itemprop="url">Linux下查看文件内容的指令</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-21T16:58:53+08:00">
                2018-06-21
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/运维日志/" itemprop="url" rel="index">
                    <span itemprop="name">运维日志</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/06/21/Linux下查看文件内容的指令/" class="leancloud_visitors" data-flag-title="Linux下查看文件内容的指令">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="Linux下查看文件内容的命令"><a href="#Linux下查看文件内容的命令" class="headerlink" title="Linux下查看文件内容的命令"></a>Linux下查看文件内容的命令</h2><h3 id="查看文件内容的命令："><a href="#查看文件内容的命令：" class="headerlink" title="查看文件内容的命令："></a>查看文件内容的命令：</h3><p>vi      编辑方式查看，可修改</p>
<p>cat     显示全部文件内容，由第一行开始显示内容，并将所有内容输出</p>
<p>tac     从最后一行倒序显示内容，并将所有内容输出</p>
<p>more    根据窗口大小，分页显示文件内容</p>
<p>less    和more类似，但其优点可以往前翻页，而且进行可以搜索字符</p>
<p>head    只显示头几行</p>
<p>tail    只显示最后几行</p>
<p>nl      类似于cat -n，显示时输出行号</p>
<p>tailf   类似于tail -f </p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/06/08/避免IDE格式化/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/08/避免IDE格式化/" itemprop="url">避免IDE格式化</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-08T15:59:40+08:00">
                2018-06-08
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/06/08/避免IDE格式化/" class="leancloud_visitors" data-flag-title="避免IDE格式化">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="避免IDE格式化"><a href="#避免IDE格式化" class="headerlink" title="避免IDE格式化"></a>避免IDE格式化</h2><p>使用@formatter:off和@formatter:on来包围不需要格式化的代码，IDE就会跳过这段的格式化。</p>
<p>// @formatter:off<br>…<br>// @formatter:on</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/06/05/Linux too many open files/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/05/Linux too many open files/" itemprop="url">Linux too many open files问题调查</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-05T14:38:14+08:00">
                2018-06-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/运维日志/" itemprop="url" rel="index">
                    <span itemprop="name">运维日志</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/06/05/Linux too many open files/" class="leancloud_visitors" data-flag-title="Linux too many open files问题调查">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>今天发现某netty服务总是报too many open files，因为是新上的服务，设备量并不多，不应该啊，T.T</p>
<h2 id="原因"><a href="#原因" class="headerlink" title="原因"></a>原因</h2><p>调查一下发生原因：<br>too many open files，字面意思上看就是打开了过多的文件，不过在linux下files并不只是文件的意思，像socket(Tcp、Udp)连接，开启监听的端口这些都属于file，所以有时候也可以叫做句柄(handle)，这个错误也可以描述为句柄数（file-handles）超出系统限制。 </p>
<p>从上述文字描述可以看出，出现这句提示的原因就是程序打开的Socket连接数量超过系统设定值。</p>
<p>既然是超过了系统的设定值，那么当前用户的设定值是多少呢？</p>
<p>用命令查一下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# ulimit -a</span><br><span class="line">core file size          (blocks, -c) 0</span><br><span class="line">data seg size           (kbytes, -d) unlimited</span><br><span class="line">scheduling priority             (-e) 0</span><br><span class="line">file size               (blocks, -f) unlimited</span><br><span class="line">pending signals                 (-i) 31203</span><br><span class="line">max locked memory       (kbytes, -l) 64</span><br><span class="line">max memory size         (kbytes, -m) unlimited</span><br><span class="line">open files                      (-n) 1024</span><br><span class="line">pipe size            (512 bytes, -p) 8</span><br><span class="line">POSIX message queues     (bytes, -q) 819200</span><br><span class="line">real-time priority              (-r) 0</span><br><span class="line">stack size              (kbytes, -s) 8192</span><br><span class="line">cpu time               (seconds, -t) unlimited</span><br><span class="line">max user processes              (-u) 31203</span><br><span class="line">virtual memory          (kbytes, -v) unlimited</span><br><span class="line">file locks                      (-x) unlimited</span><br></pre></td></tr></table></figure></p>
<p>或者</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# ulimit -n</span><br><span class="line">1024</span><br></pre></td></tr></table></figure>
<p>当前用户open files居然才只有1024，查看一下当前系统已开启的文件数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# lsof | wc -l</span><br><span class="line">-bash: lsof: command not found</span><br></pre></td></tr></table></figure>
<p>0.0，没有安装lsof，yum安装一下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# yum install lsof</span><br><span class="line">Loaded plugins: fastestmirror</span><br><span class="line">base                                                     | 3.6 kB     00:00</span><br><span class="line">epel/x86_64/metalink                                     | 6.7 kB     00:00</span><br><span class="line">epel                                                     | 3.2 kB     00:00</span><br><span class="line">extras                                                   | 3.4 kB     00:00</span><br><span class="line">updates                                                  | 3.4 kB     00:00</span><br><span class="line">(1/3): epel/x86_64/updateinfo                              | 932 kB   00:00</span><br><span class="line">(2/3): updates/7/x86_64/primary_db                         | 2.0 MB   00:01</span><br><span class="line">(3/3): epel/x86_64/primary                                 | 3.5 MB   00:01</span><br><span class="line">Loading mirror speeds from cached hostfile</span><br><span class="line"> * base: mirrors.aliyun.com</span><br><span class="line"> * epel: mirrors.aliyun.com</span><br><span class="line"> * extras: mirrors.aliyun.com</span><br><span class="line"> * updates: mirrors.aliyun.com</span><br><span class="line">epel                                                                12585/12585</span><br><span class="line">Resolving Dependencies</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package lsof.x86_64 0:4.87-5.el7 will be installed</span><br><span class="line">--&gt; Finished Dependency Resolution</span><br><span class="line"></span><br><span class="line">Dependencies Resolved</span><br><span class="line"></span><br><span class="line">================================================================================</span><br><span class="line"> Package         Arch              Version                Repository       Size</span><br><span class="line">================================================================================</span><br><span class="line">Installing:</span><br><span class="line"> lsof            x86_64            4.87-5.el7             base            331 k</span><br><span class="line"></span><br><span class="line">Transaction Summary</span><br><span class="line">================================================================================</span><br><span class="line">Install  1 Package</span><br><span class="line"></span><br><span class="line">Total download size: 331 k</span><br><span class="line">Installed size: 927 k</span><br><span class="line">Is this ok [y/d/N]: y</span><br><span class="line">Downloading packages:</span><br><span class="line">lsof-4.87-5.el7.x86_64.rpm                                 | 331 kB   00:00</span><br><span class="line">Running transaction check</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded</span><br><span class="line">Running transaction</span><br><span class="line">  Installing : lsof-4.87-5.el7.x86_64                                       1/1</span><br><span class="line">  Verifying  : lsof-4.87-5.el7.x86_64                                       1/1</span><br><span class="line"></span><br><span class="line">Installed:</span><br><span class="line">  lsof.x86_64 0:4.87-5.el7</span><br><span class="line"></span><br><span class="line">Complete!</span><br></pre></td></tr></table></figure>
<p>再查看该进程已打开的文件数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># wc -l 统计输出信息的行数</span><br><span class="line"># 因为lsof -p pid已经过滤到该进程已打开的文件数，一行信息对应一个文件，所以也就是文件的个数。</span><br><span class="line">[root@localhost ~]# lsof -p pid | wc -l</span><br><span class="line">2858</span><br></pre></td></tr></table></figure>
<h2 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h2><p>临时提高一下open files数值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ulimit -n 65535</span><br></pre></td></tr></table></figure>
<p>再查看发现open files已更新，但是这种一重启就会还原</p>
<p>永久更改open files的方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/security/limits.conf  </span><br><span class="line"># insert last line</span><br><span class="line"># * 标识所有用户，也可单独设置某一用户，如test soft nofile 65535</span><br><span class="line">* soft nofile 65535  </span><br><span class="line">* hard nofile 65535</span><br></pre></td></tr></table></figure>
<h2 id="深度调查"><a href="#深度调查" class="headerlink" title="深度调查"></a>深度调查</h2><p>使用命令打印程序open files详细日志，进行问题排查。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost /]# lsof -p pid &gt; openfiles.log</span><br><span class="line">[root@localhost /]# tail -f ./openfiles.log</span><br><span class="line"></span><br><span class="line">java    5275 root 2864u     IPv6           23540972       0t0       TCP localhost.localdomain:45214-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">java    5275 root 2865u     IPv6           23540973       0t0       TCP localhost.localdomain:45216-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">java    5275 root 2866u  a_inode                0,9         0      5815 [eventpoll]</span><br><span class="line">java    5275 root 2867u     IPv6           23541135       0t0       TCP localhost.localdomain:45398-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">java    5275 root 2868u     IPv6           23541136       0t0       TCP localhost.localdomain:45401-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">java    5275 root 2869r     FIFO                0,8       0t0  23541164 pipe</span><br><span class="line">java    5275 root 2870w     FIFO                0,8       0t0  23541164 pipe</span><br><span class="line">java    5275 root 2871u  a_inode                0,9         0      5815 [eventpoll]</span><br><span class="line">java    5275 root 2872u     IPv6           23541165       0t0       TCP localhost.localdomain:45433-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">java    5275 root 2873u     IPv6           23541166       0t0       TCP localhost.localdomain:45434-&gt;192.168.0.199:19092 (ESTABLISHED)</span><br><span class="line">....</span><br></pre></td></tr></table></figure>
<p>发现有很多连接处在ESTABLISHED（通讯中）状态，应该是硬件频繁连接，netty持有的channel并没有被释放。</p>
<h2 id="程序解决方案"><a href="#程序解决方案" class="headerlink" title="程序解决方案"></a>程序解决方案</h2><p>服务添加idle处理，硬件心跳中断一段时间后自动将channel关闭。</p>
<h2 id="TCP端口状态说明"><a href="#TCP端口状态说明" class="headerlink" title="TCP端口状态说明"></a>TCP端口状态说明</h2><h3 id="1、LISTENING状态"><a href="#1、LISTENING状态" class="headerlink" title="1、LISTENING状态"></a>1、LISTENING状态</h3><p>FTP服务启动后首先处于侦听（LISTENING）状态。</p>
<h3 id="2、ESTABLISHED状态"><a href="#2、ESTABLISHED状态" class="headerlink" title="2、ESTABLISHED状态"></a>2、ESTABLISHED状态</h3><p>ESTABLISHED的意思是建立连接。表示两台机器正在通信。</p>
<h3 id="3、CLOSE-WAIT"><a href="#3、CLOSE-WAIT" class="headerlink" title="3、CLOSE_WAIT"></a>3、CLOSE_WAIT</h3><p>对方主动关闭连接或者网络异常导致连接中断，这时我方的状态会变成CLOSE_WAIT 此时我方要调用close()来使得连接正确关闭。</p>
<h3 id="4、TIME-WAIT"><a href="#4、TIME-WAIT" class="headerlink" title="4、TIME_WAIT"></a>4、TIME_WAIT</h3><p>我方主动调用close()断开连接，收到对方确认后状态变为TIME_WAIT。TCP协议规定TIME_WAIT状态会一直持续2MSL(即两倍的分段最大生存期)，以此来确保旧的连接状态不会对新连接产生影响。处于TIME_WAIT状态的连接占用的资源不会被内核释放，所以作为服务器，在可能的情况下，尽量不要主动断开连接，以减少TIME_WAIT状态造成的资源浪费。目前有一种避免TIME_WAIT资源浪费的方法，就是关闭socket的LINGER选项。但这种做法是TCP协议不推荐使用的，在某些情况下这个操作可能会带来错误。</p>
<h3 id="5、SYN-SENT状态"><a href="#5、SYN-SENT状态" class="headerlink" title="5、SYN_SENT状态"></a>5、SYN_SENT状态</h3><p>SYN_SENT状态表示请求连接，当你要访问其它的计算机的服务时首先要发个同步信号给该端口，此时状态为SYN_SENT，如果连接成功了就变为 ESTABLISHED，此时SYN_SENT状态非常短暂。但如果发现SYN_SENT非常多且在向不同的机器发出，那你的机器可能中了冲击波或震荡波之类的病毒了。这类病毒为了感染别的计算机，它就要扫描别的计算机，在扫描的过程中对每个要扫描的计算机都要发出了同步请求，这也是出现许多SYN_SENT的原因。</p>
<p>根据TCP协议定义的3次握手断开连接规定,发起Socket主动关闭的一方Socket将进入TIME_WAIT状态，TIME_WAIT状态将持续2个MSL(Max Segment Lifetime)，在Windows下默认为4分钟,即240秒，TIME_WAIT状态下的socket不能被回收使用。具体现象是对于一个处理大量短连接的服务器，如果是由服务器主动关闭客户端的连接,将导致服务器端存在大量的处于TIME_WAIT状态的socket，甚至比处于Established状态下的socket多的多，严重影响服务器的处理能力,甚至耗尽可用的socket，停止服务。TIME_WAIT是TCP协议用以保证被重新分配的socket不会受到之前残留的延迟重发报文影响的机制，是必要的逻辑保证。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/05/17/使用logrotate对nginx日志按天进行分割/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/05/17/使用logrotate对nginx日志按天进行分割/" itemprop="url">使用logrotate对nginx日志按天进行分割</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-17T11:04:43+08:00">
                2018-05-17
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/运维日志/" itemprop="url" rel="index">
                    <span itemprop="name">运维日志</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/05/17/使用logrotate对nginx日志按天进行分割/" class="leancloud_visitors" data-flag-title="使用logrotate对nginx日志按天进行分割">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="情景"><a href="#情景" class="headerlink" title="情景"></a>情景</h2><p>今天运维大哥来找，某某服务器磁盘报警啦。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">df -m</span><br></pre></td></tr></table></figure>
<p>看了一下/dev/vda1果然快满了，磁盘使用率97%。。。</p>
<p>没办法先紧急清理一下log吧</p>
<p>查一下那个目录占用空间比较大</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">du -h --max-depth=1</span><br></pre></td></tr></table></figure>
<p>噼里啪啦一阵之后发现nginx下的access.log居然有13G，这还能忍？赶紧压缩移到别的地方~</p>
<h2 id="原因"><a href="#原因" class="headerlink" title="原因"></a>原因</h2><p>nginx会按照nginx.conf的配置生成access.log和error.log，随着访问量的增长，日志文件会越来越大，既会影响访问的速度(写入日志时间延长)，<br>也会增加查找日志的难度，nginx没有这种按天或更细粒度生成日志的机制。</p>
<p>但是线上的服务器应该都配置了logrotate,为什么会一直累加该文件，赶紧看了下果然这台服务器上没有配置T.T。</p>
<p>只好自己配一下了，省的以后想查日志还得自己切分。</p>
<h2 id="logrotate配置"><a href="#logrotate配置" class="headerlink" title="logrotate配置"></a>logrotate配置</h2><p>logrotate程序是一个日志文件管理工具。用来把旧的日志文件删除，并创建新的日志文件，我们把它叫做“转储”。我们可以根据日志文件的大小，也可以根据其天数来转储，这个过程一般通过 cron 程序来执行。<br>logrotate程序还可以用于压缩日志文件，以及发送日志到指定的E-mail 。</p>
<h2 id="配置选项说明"><a href="#配置选项说明" class="headerlink" title="配置选项说明"></a>配置选项说明</h2><p>compress：通过gzip 压缩转储旧的日志<br>nocompress：不需要压缩时，用这个参数<br>copytruncate：用于还在打开中的日志文件，把当前日志备份并截断<br>nocopytruncate：备份日志文件但是不截断<br>create mode owner group：使用指定的文件模式创建新的日志文件<br>nocreate：不建立新的日志文件<br>delaycompress：和 compress 一起使用时，转储的日志文件到下一次转储时才压缩<br>nodelaycompress：覆盖 delaycompress 选项，转储同时压缩<br>errors address：专储时的错误信息发送到指定的Email 地址<br>ifempty：即使是空文件也转储，这个是 logrotate 的缺省选项<br>notifempty：如果是空文件的话，不转储<br>mail address：把转储的日志文件发送到指定的E-mail 地址<br>nomail：转储时不发送日志文件<br>olddir directory：转储后的日志文件放入指定的目录，必须和当前日志文件在同一个文件系统<br>noolddir：转储后的日志文件和当前日志文件放在同一个目录下<br>prerotate/endscript：在转储以前需要执行的命令可以放入这个对，这两个关键字必须单独成行<br>postrotate/endscript：在转储以后需要执行的命令可以放入这个对，这两个关键字必须单独成行<br>sharedscripts：所有的日志文件都轮转完毕后统一执行一次脚本<br>daily：指定转储周期为每天<br>weekly：指定转储周期为每周<br>monthly：指定转储周期为每月<br>rotate count：指定日志文件删除之前转储的次数，0 指没有备份，5 指保留5 个备份<br>size size：当日志文件到达指定的大小时才转储，Size 可以指定 bytes (缺省)以及KB (sizek)或者MB</p>
<h2 id="命令参数说明"><a href="#命令参数说明" class="headerlink" title="命令参数说明"></a>命令参数说明</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># logrotate –help</span></span><br><span class="line">Usage: logrotate [OPTION...] &lt;configfile&gt;</span><br><span class="line">  -d, --debug               调试模式，输出调试结果，并不执行。隐式-v参数</span><br><span class="line">  -f, --force               强制模式，对所有相关文件进行rotate</span><br><span class="line">  -m, --mail=<span class="built_in">command</span>        发送邮件 (instead of `/bin/mail<span class="string">')</span></span><br><span class="line"><span class="string">  -s, --state=statefile     状态文件，对于运行在不同用户情况下有用</span></span><br><span class="line"><span class="string">  -v, --verbose             显示debug信息</span></span><br></pre></td></tr></table></figure>
<h2 id="logrotate配置文件默认位置："><a href="#logrotate配置文件默认位置：" class="headerlink" title="logrotate配置文件默认位置："></a>logrotate配置文件默认位置：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/etc/logrotate.conf 通用配置文件，可以定义全局默认使用的选项。 </span><br><span class="line">/etc/logrotate.d/nginx 自定义服务配置文件</span><br><span class="line"></span><br><span class="line">/usr/<span class="built_in">local</span>/nginx/logs/*.<span class="built_in">log</span></span><br><span class="line">/usr/<span class="built_in">local</span>/nginx/logs/XXX/*.<span class="built_in">log</span>  <span class="comment">#指定日志文件位置，可用正则匹配</span></span><br></pre></td></tr></table></figure>
<p>/etc/logrotate.d/nginx</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">nginx &#123;</span><br><span class="line">    daily           <span class="comment">#调用频率，有：daily，weekly，monthly可选</span></span><br><span class="line">    rotate 30       <span class="comment">#一次将存储30个归档日志。对于第31个归档，时间最久的归档将被删除。</span></span><br><span class="line">    compress        <span class="comment">#通过gzip 压缩转储旧的日志 </span></span><br><span class="line">    sharedscripts   <span class="comment">#所有的日志文件都轮转完毕后统一执行一次脚本</span></span><br><span class="line">    postrotate      <span class="comment">#执行命令的开始标志</span></span><br><span class="line">        <span class="keyword">if</span> [ -f /usr/<span class="built_in">local</span>/nginx/logs/nginx.pid ]; <span class="keyword">then</span></span><br><span class="line">            <span class="built_in">kill</span> -USR1 `cat /usr/<span class="built_in">local</span>/nginx/logs/nginx.pid`</span><br><span class="line">            <span class="comment">#不是中止Nginx的进程，而是传递给它信号重新生成日志，如果nginx没启动不做操作</span></span><br><span class="line">        <span class="keyword">fi</span></span><br><span class="line">    endscript <span class="comment">#执行命令的结束标志</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="测试配置手动执行logrotate"><a href="#测试配置手动执行logrotate" class="headerlink" title="测试配置手动执行logrotate"></a>测试配置手动执行logrotate</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 强制执行（-f = force），冗长的-v(-v =verbose），注意调试信息默认携带-v；</span></span><br><span class="line">logrotate -vf /etc/logrotate.d/nginx</span><br></pre></td></tr></table></figure>
<h2 id="输出如下，查看日志文件夹生成已压缩的日志："><a href="#输出如下，查看日志文件夹生成已压缩的日志：" class="headerlink" title="输出如下，查看日志文件夹生成已压缩的日志："></a>输出如下，查看日志文件夹生成已压缩的日志：</h2><p><img src="/upload/logrotate/logrotate_1.png" alt="logrotate_1.png"><br><img src="/upload/logrotate/logrotate_2.png" alt="logrotate_2.png"></p>
<h2 id="Cron定时执行logrotate"><a href="#Cron定时执行logrotate" class="headerlink" title="Cron定时执行logrotate"></a>Cron定时执行logrotate</h2><p>配置文件测试完毕，logrotate实际使用一般都是通过cron来定时执行。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># cat /etc/cron.daily/logrotate</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">/usr/sbin/logrotate /etc/logrotate.conf &gt;/dev/null 2&gt;&amp;1</span><br><span class="line">EXITVALUE=$?</span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$EXITVALUE</span> != 0 ]; <span class="keyword">then</span></span><br><span class="line">    /usr/bin/logger -t logrotate <span class="string">"ALERT exited abnormally with [<span class="variable">$EXITVALUE</span>]"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"><span class="built_in">exit</span> 0</span><br></pre></td></tr></table></figure>
<p>默认的logrotate已经放在/etc/cron.daily/logrotate下，让corn每天执行一次logrotate程序。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/04/16/fastjson反序列化对象中存在Set，报解析异常错误处理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/04/16/fastjson反序列化对象中存在Set，报解析异常错误处理/" itemprop="url">fastjson反序列化对象中存在Set，报解析异常错误处理</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-16T11:10:25+08:00">
                2018-04-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/04/16/fastjson反序列化对象中存在Set，报解析异常错误处理/" class="leancloud_visitors" data-flag-title="fastjson反序列化对象中存在Set，报解析异常错误处理">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="情景："><a href="#情景：" class="headerlink" title="情景："></a>情景：</h2><p>使用fastjson替换jackson，作为json解析器，某对象序列化到Redis中后格式为：</p>
<pre><code class="bash">{
    <span class="string">"@type"</span>: <span class="string">"com.diditech.iov.alarm.domain.AlarmChartQueryParam"</span>,
    <span class="string">"almTypeSet"</span>: Set[1, 2, 3],
    <span class="string">"almYear"</span>: <span class="string">"2018"</span>,
    <span class="string">"chartType"</span>: 1,
    <span class="string">"defaultFlag"</span>: 1,
    <span class="string">"type"</span>: 2
}
</code></pre>
<p>其中”almTypeSet”: Set[1, 2, 3]，字段类型为Set<integer>，反序列时报错，如下图：<br><img src="/upload/fastjson/fastjson-serializable1.png" alt="fastjson-serializable1.png"></integer></p>
<p>将字段类型更换为List<integer>后，问题暂时解决，但是为什么Set反序列化会出现问题？</integer></p>
<p>比对List和Set生成的Json数据：<br>List<integer>   ————-&gt;    [1, 2, 3]<br>Set<integer>    ————-&gt;    Set[1, 2, 3]</integer></integer></p>
<p>Set类型生成的json数据中写入了Class的类型，因在使用fastjson替换原Spring Boot默认的jackson，实现了Redis序列化的接口，重写了序列化和反序列化的方法，其中有这么一句，JSON.toJSONBytes(o, SerializerFeature.WriteClassName)，SerializerFeature.WriteClassName表示序列化时会写入类名，完整代码如下：</p>
<pre><code class="bash">public class FastJsonRedisSerializer implements RedisSerializer&lt;Object&gt; {
    @Override
    public byte[] serialize(Object o) throws SerializationException {
        <span class="keyword">if</span> (o == null) <span class="built_in">return</span> null;
        <span class="built_in">return</span> JSON.toJSONBytes(o, SerializerFeature.WriteClassName);
    }

    @Override
    public Object deserialize(byte[] bytes) throws SerializationException {
        <span class="keyword">if</span> (bytes == null) <span class="built_in">return</span> null;
        <span class="built_in">return</span> JSON.parse(bytes);
    }
}
</code></pre>
<p>但是依然不清楚为何Set不能反序列化，而List就可以，继续追查后找到解决方案，如下：</p>
<p>在GitHub fastjson Issues #386，发现有人提过相同的问题</p>
<pre><code class="bash">ParserConfig.getGlobalInstance().setAsmEnable(<span class="literal">false</span>);//关闭asm.
</code></pre>
<p>关闭asm后，再进行反序列化就没有问题了。</p>
<p>asm：获取java bean的属性值，需要调用反射，fastjson引入了asm的来避免反射导致的开销。fastjson内置的asm是基于objectweb asm 3.3.1改造的，只保留必要的部分，fastjson asm部分不到1000行代码，引入了asm的同时不导致大小变大太多。</p>
<p>未待完续，asm待深入了解。。。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/03/05/Hibernate-validator应用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/03/05/Hibernate-validator应用/" itemprop="url">Hibernate-validator应用</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-03-05T09:52:56+08:00">
                2018-03-05
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/03/05/Hibernate-validator应用/" class="leancloud_visitors" data-flag-title="Hibernate-validator应用">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://hunfan.top/2018/02/19/svn-relocate/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="混饭">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="混饭's Notes">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/02/19/svn-relocate/" itemprop="url">svn-relocate</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-02-19T20:13:57+08:00">
                2018-02-19
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2018/02/19/svn-relocate/" class="leancloud_visitors" data-flag-title="svn-relocate">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="TortoiseSvn-relocate"><a href="#TortoiseSvn-relocate" class="headerlink" title="TortoiseSvn-relocate"></a>TortoiseSvn-relocate</h3><p><img src="/upload/svn-relocate/1.png" alt="1.png"></p>
<p><img src="/upload/svn-relocate/2.png" alt="1.png"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/4/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/page/6/">6</a><a class="extend next" rel="next" href="/page/6/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="混饭" />
          <p class="site-author-name" itemprop="name">混饭</p>
           
              <p class="site-description motion-element" itemprop="description">重度拖延症患者(-__-)b</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives/">
            
                <span class="site-state-item-count">52</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">45</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hf-hf" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                    
                      GitHub
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://gitee.com/hf-hf" target="_blank" title="Gitee">
                  
                    <i class="fa fa-fw fa-gitee"></i>
                  
                    
                      Gitee
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">混饭</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" href="https://coding.net/pages">Hosted by CODING Pages</a> 强力驱动</div>



        
<div class="busuanzi-count">
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fastclick/1.0.6/fastclick.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazyload/1.9.3/jquery.lazyload.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>

  
  <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>





  


  




	





  





  








  




  
  
  
    
  
  <link rel="stylesheet" href="//cdn.bootcss.com/instantsearch.js/1.5.0/instantsearch.min.css">

  
  
    
  
  <script src="//cdn.bootcss.com/instantsearch.js/1.5.0/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.2"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("FbdjjSByqhjHC2t0f5DiTzXi-gzGzoHsz", "EhyT8E3CKzF9CQcem5hx7ftx");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>
